from appium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as Ec


class Base():
    #初始化
    def __init__(self):
        cap={
              "platformName": "Android",
              "appium:deviceName": "emulator-5554",
              "appium:automationName": "uiautomator2",
              "appium:appPackage": "com.xiachufang",
              "appium:appActivity": ".activity.home.HomeActivity",
              "appium:noReset": True
            }
        #连接
        self.driver=webdriver.Remote('http://127.0.0.1:4723/wd/hub',cap)
        #隐式等待
        self.driver.implicitly_wait(10)
    #找元素
    def find_ele(self,loc):
        ele=self.driver.find_element(*loc)
        return ele
    #显示等待
    def find_xian(self,loc):
        ele=WebDriverWait(self.driver,10).until(Ec.presence_of_element_located(loc))
        return ele
    #轻敲
    def find_qing(self,a,b):
        self.driver.tap([(a,b)],10)
    #滑动
    def find_hua(self,a,b,c,d):
        self.driver.swipe(a,b,c,d,200)
    #截图
    def find_jie(self,a):
        ele=self.driver.save_screenshot(a)
        return ele
    #退出
    def find_tui(self):
        self.driver.quit()